package com.pic.mgt.haishin;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.pic.mgt.scheduler.ScheduleAutoJobException;
import com.pic.mgt.scheduler.SchedulerException;
import com.pic.mgt.scheduler.SchedulerImpl;
import com.pic.mgt.unit.Business;

public final class HaishinSchedulerImpl extends SchedulerImpl
									implements HaishinScheduler {
	private final Class<HaishinExecutionQuartzJobBean>
			haishinExecutionJobClass = HaishinExecutionQuartzJobBean.class;
	
	public String[] scheduleSimpleBusiness(Business business,
									   	   Date executionTime)
										throws SchedulerException {
		// 排程名稱
		String scheduleName = business.getTargetFilename();
		// 排程群組名稱 
		String scheduleGroupName = business.getBusinessName();
		// Job Data
		Map<String,Business> jobData = new HashMap<String,Business>();
		jobData.put(jobDataBusinessKey, business);
		
		try {
			// throws ScheduleAutoJobException
			super.quartzAutoJob.scheduleSimpleJob(executionTime,
											haishinExecutionJobClass,
											jobData,
											scheduleName,
											scheduleGroupName);
		} catch (ScheduleAutoJobException e) {
			throw new SchedulerException(
					"Scheduling business '" + business.getTargetFile() +
					"' failed.", e);
		}
		
		return new String[] {scheduleName, scheduleGroupName};
	}
}
